#!/bin/sh

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
TERM=linux
PS2='>'

#/bin/echo "Mount root system ......"
#install /proc
/bin/mount -n -t proc none /proc 1>/dev/null 2>&1
#reinstall root file system by read/write mode and need /etc/fstab
/bin/mount -a  1>/dev/null 2>&1
/bin/mount -n -o remount,rw /  1>/dev/null 2>&1
#reinstall /proc
/bin/mount -n -o remount,rw -t proc none /proc  1>/dev/null 2>&1

#/bin/echo "Check file system ......"
/sbin/fsck -T -R -A -a  1>/dev/null 2>&1

VERSION=`cat /etc/issue`
PS1="Mini $VERSION> "
export PATH TERM PS1 PS2 VERSION

#/bin/echo "Mkdir the usr dir ......" 
/bin/mkdir -p /usr/lib 1>/dev/null 2>&1
/bin/mkdir -p /usr/tmp 1>/dev/null 2>&1
/bin/mkdir -p /usr/lock 1>/dev/null 2>&1
/bin/mkdir -p /usr/run 1>/dev/null 2>&1
/bin/mkdir -p /usr/spool 1>/dev/null 2>&1
/bin/mkdir -p /usr/log/httpd 1>/dev/null 2>&1

cd /

#/bin/echo "Tar init packages ......"
packages=`find /packages/ -name "*.tgz"`
for i in $packages
do 
	/bin/tar xzf $i 1>/dev/null 2>&1
done
/bin/sync 1>/dev/null 2>&1

/sbin/ldconfig -v >/dev/null 2>&1

#/bin/echo "Update dev system ......"
/sbin/mount LABEL=CONTENT /ldisk 1>/dev/null 2>&1
upgrade=`find /ldisk/upgrade/ -name "*.tgz"`
for i in $upgrade
do
	/bin/tar xzf $i 1>/dev/null 2>&1
done
/bin/sync 1>/dev/null 2>&1

if [ -e /ldisk/upgrade/upgrade.sh ]
then
	/bin/chmod +x /ldisk/upgrade/upgrade.sh 1>/dev/null 2>&1
	/ldisk/upgrade/upgrade.sh 1>/dev/null 2>&1
fi

/sbin/ldconfig -v >/dev/null 2>&1

/bin/hostname Mini
